import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "tailwindcss";
import path from "path";
const NODE_ENV = process.env.NODE_ENV;
// https://vite.dev/config/
export default ({ mode }: { mode: any }) => {
  const env = loadEnv(mode, process.cwd());
  const { VITE_APP_HOST, VITE_APP_PORT, VITE_APP_MODE, VITE_BUILD_BASE_API } =
    env;
  return defineConfig({
    base: NODE_ENV !== "development" ? VITE_BUILD_BASE_API : "/",
    server: {
      host: VITE_APP_HOST,
      port: ~~VITE_APP_PORT, // 设置服务启动端口号
      open: false, // 设置服务启动时是否自动打开浏览器
      cors: true,
    },
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
      },
      extensions: [".js", ".ts", ".json", ".tsx"], // 导入时想要省略的扩展名列表
    },
    // 新增 css 配置
    css: {
      postcss: {
        plugins: [tailwindcss()],
      },
    },

    plugins: [react()],
  });
};
